using System.Data.SqlClient;
using CoreLibrary.Sql;

namespace Entities.DataBase.Sql {

    internal class UpdateBeforeInsertAfter : ISqlUpdator<bool> {
        
        private readonly int _right;
        private readonly string _tableName;

        public UpdateBeforeInsertAfter(int right, string tableName) {
            _right = right;
            _tableName = tableName;
        }

        public string GetSQL() {
            return string.Format(
               @"
                UPDATE {0} SET RID = RID + 2 WHERE RID > @right;
                UPDATE {0} SET LID = LID + 2 WHERE LID > @right;
               ", 
               _tableName
            );
        }

        public void SetParameters(SqlCommand command) {
            command.Parameters.AddWithValue("@right",_right);
        }

        public bool GetResult(SqlConnection conn, int result) {
            return result >= 0;
        }

    }

}